// devops/pages/apply/apply.js
import service from '../../../utils/request'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    steps: [
      {
        text: '提交申请',
        desc: '',
        activeIcon: 'success',
      },
      {
        text: '审核通过',
        desc: '',
        activeIcon: 'success',
      },
      {
        text: '预约安装中',
        desc: '',
        activeIcon: 'success',
      },
      {
        text: '安装中',
        desc: '',
        activeIcon: 'success',
      },
      {
        text: '安装完成',
        desc: '',
        activeIcon: 'checked',
      },
    ],
    id:'',
    info: {},
    color: '#07c160',
    active: 0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      id: options.id
    })
    this.getQuery()
  },

  //详情 
  getQuery(){
    let that = this
    let id = this.data.id
    service("POST","/devops/apply/info",id).then(res => {
      let data = res.data.info
      console.log('info', data)
      let active = data.state == 0 ? 0 : data.state == 2 ? 1: data.state == 3 ? 2 : data.state == 4 ? 3 : data.state == 5 ? 3: 0
      if(data.state == 5){
        that.setData({
          ["steps[3]"]:{activeIcon: 'clear', text: '安装失败'} ,
          color: '#f34f0f'
        })
      }
      if(data.state == 2){
        if(data.payment==2){
          that.setData({
            ["steps[1]"]:{activeIcon: 'success', text: '审核通过',desc: '已缴费'} ,
            // color: '#f34f0f'
          })
        }else{
          that.setData({
            ["steps[1]"]:{activeIcon: 'success', text: '审核通过',desc: '未缴费'} ,
            color: '#f34f0f'
          })
        }
      }else if(data.state == 7){
        that.setData({
          ["steps[1]"]:{activeIcon: 'clear', text: '审核不通过'} ,
          color: '#f34f0f'
        })
      }
     that.setData({
       info: res.data.info,
       active: active
     })
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})